import {getAccountInfo, getUserInfo} from "@/api/system";
import axios from "axios";

const user = {
    state: {
        info:{},
        accountInfo:{},
        isGetInfo:false

    },
    mutations: {
        setInfo(state,infos){
            state.info = infos.userInfo
            state.accountInfo = infos.accountInfo
            state.isGetInfo = !state.isGetInfo
        },
        setIsGetInfo(state){
            state.isGetInfo = !state.isGetInfo
        },
    },
    actions: {
        GetUserInfo({commit}){
            return new Promise((resolve, reject) =>{
                axios.all([getUserInfo(),getAccountInfo()])
                    .then(axios.spread(function (res1, res2){
                        let infos = {
                            userInfo:res1.data,
                            accountInfo: res2.data
                        }
                        commit('setInfo', infos);
                        resolve(res1)
                    })).catch(err=>{
                    console.log(err)
                    reject(err)
                })
                // getUserInfo().then(res =>{
                //     commit('setInfo',res.data);
                //     resolve(res)
                // }).catch(err=>{
                //     console.log(err)
                //     reject(err)
                // })
            })
        }
    },
    getters:{

    }
}

export default user

